package com.china08.yxyapi.repository.db;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.china08.yxyapi.entity.db.sws.SwsSettingSlidersForApp;

public interface SwsSettingSlidersForAppRepository extends JpaRepository<SwsSettingSlidersForApp, String> {

    @Query(value = " SELECT MAX(order_num) FROM  yxy_sws.sws_setting_sliders_for_app WHERE school_id = ? ", nativeQuery = true)
    Integer maxOrderNum(String schoolId);

    SwsSettingSlidersForApp findById(String id);

    Page<SwsSettingSlidersForApp> findBySchoolId(String schoolId, Pageable pageable);

    List<SwsSettingSlidersForApp> findTop6BySchoolIdOrderByOrderNumDesc(String schoolId);

    @Query(value = " select * from yxy_sws.sws_setting_sliders_for_app t1 where t1.school_id = ? and t1.order_num < ? order by t1.order_num desc limit 1", nativeQuery = true)
    List<SwsSettingSlidersForApp> findTop1BySchoolIdAndOrderNumGtOrderByOrderNum(String schoolId, Integer orderNum);

    @Query(value = " select * from yxy_sws.sws_setting_sliders_for_app t1 where t1.school_id = ? and t1.order_num > ? order by t1.order_num asc limit 1 ", nativeQuery = true)
    List<SwsSettingSlidersForApp> findTop1BySchoolIdAndOrderNumLtOrderByOrderNum(String schoolId, Integer orderNum);
}
